/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import {Platform, StyleSheet, Button, View, NativeModules, NativeAppEventEmitter, NativeEventEmitter, DeviceEventEmitter, PermissionsAndroid} from 'react-native';

import {AudioRecorder, AudioUtils} from 'react-native-audio';

import Sound from 'react-native-sound'; // 播放声音组件

import Video from 'react-native-video'; // 播放声音组件

import BleManager from 'react-native-ble-manager';
import { stringToBytes } from 'convert-string';
// Convert data to byte array before write/writeWithoutResponse
const data = stringToBytes('shimuhui');
const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);

const Manager = NativeModules.PlayingViewController;

var playSound;


const ToastExample = NativeModules.ToastExample;

var readServiceUUID = [];
var readCharacteristicUUID = [];   
var writeWithResponseServiceUUID = [];
var writeWithResponseCharacteristicUUID = [];
var writeWithoutResponseServiceUUID = [];
var writeWithoutResponseCharacteristicUUID = [];
var nofityServiceUUID = [];
var nofityCharacteristicUUID = [];  


/** ios系统从蓝牙广播信息中获取蓝牙MAC地址 */
function getMacAddressFromIOS(data) {
  let macAddressInAdvertising = data.advertising.kCBAdvDataManufacturerMacAddress;
  //为undefined代表此蓝牙广播信息里不包括Mac地址
  if(!macAddressInAdvertising){  
      return;
  }
  macAddressInAdvertising = macAddressInAdvertising.replace("<","").replace(">","").replace(" ","");
  if(macAddressInAdvertising != undefined && macAddressInAdvertising != null && macAddressInAdvertising != '') {
  macAddressInAdvertising = swapEndianWithColon(macAddressInAdvertising);
  }
  return macAddressInAdvertising;
};
/**
* ios从广播中获取的mac地址进行大小端格式互换，并加上冒号:
* @param str         010000CAEA80
* @returns string    80:EA:CA:00:00:01
*/
function swapEndianWithColon(str){
  let format = '';
  let len = str.length;
  for(let j = 2; j <= len; j = j + 2){
      format += str.substring(len-j, len-(j-2));
      if(j != len) {
          format += ":";
      }
  }
  return format.toUpperCase();
}
//获取Notify、Read、Write、WriteWithoutResponse的serviceUUID和characteristicUUID
function getUUID(peripheralInfo){       
  
  for(let item of peripheralInfo.characteristics){  
      //请根据具体需要是否转成128位的，ios有些设备需要传16位的才能正常通信
      //item.service = this.fullUUID(item.service);
      item.characteristic = fullUUID(item.characteristic); 
      if(Platform.OS == 'android'){  
          if(item.properties.Notify == 'Notify'){    
              nofityServiceUUID.push(item.service);     
              nofityCharacteristicUUID.push(item.characteristic);
          }
          if(item.properties.Read == 'Read'){
              readServiceUUID.push(item.service);
              readCharacteristicUUID.push(item.characteristic);
          }
          if(item.properties.Write == 'Write'){
              writeWithResponseServiceUUID.push(item.service);
              writeWithResponseCharacteristicUUID.push(item.characteristic);
          }
          if(item.properties.Write == 'WriteWithoutResponse'){
              writeWithoutResponseServiceUUID.push(item.service);
              writeWithoutResponseCharacteristicUUID.push(item.characteristic);
          }               
      }else{  //ios
          for(let property of item.properties){
              if(property == 'Notify'){
                  nofityServiceUUID.push(item.service);
                  nofityCharacteristicUUID.push(item.characteristic);
              }
              if(property == 'Read'){
                  readServiceUUID.push(item.service);
                  readCharacteristicUUID.push(item.characteristic);
              }
              if(property == 'Write'){
                  writeWithResponseServiceUUID.push(item.service);
                  writeWithResponseCharacteristicUUID.push(item.characteristic);
              }
              if(property == 'WriteWithoutResponse'){
                  writeWithoutResponseServiceUUID.push(item.service);
                  writeWithoutResponseCharacteristicUUID.push(item.characteristic);
              }                  
          }
      }
  }
}
/**
* 请根据具体需要是否转成128位的，ios有些设备需要传16位的才能正常通信
* Converts UUID to full 128bit.
* 
* @param {UUID} uuid 16bit, 32bit or 128bit UUID.
* @returns {UUID} 128bit UUID.
*/
function fullUUID(uuid) {
  if (uuid.length === 4){
      return '0000' + uuid.toUpperCase() + '-0000-1000-8000-00805F9B34FB'
   }             
  if (uuid.length === 8) {
      return uuid.toUpperCase() + '-0000-1000-8000-00805F9B34FB'
   }            
   return uuid.toUpperCase()
} 

type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
    super(props);
    this.prepareRecordingPath = this.prepareRecordingPath.bind(this);     //执行录音的方法
    this.checkPermission = this.checkPermission.bind(this);               //检测是否授权
    this.record = this.record.bind(this);                                 //录音
    this.stop = this.stop.bind(this);                                     //停止
    this.play = this.play.bind(this);                                     //播放
    this.pause = this.pause.bind(this);                                   //暂停
    this.finishRecording = this.finishRecording.bind(this);
    this.playSound = this.playSound.bind(this);
    this.playSoundPause = this.playSoundPause.bind(this);
    this.playSoundPlay = this.playSoundPlay.bind(this);
    this.playSoundPrev = this.playSoundPrev.bind(this);
    this.playSoundNext = this.playSoundNext.bind(this);
    this.state = {
      currentTime: 0.0, //开始录音到现在的持续时间
      recording: false, //是否正在录音
      stoppedRecording: false, //是否停止了录音
      finished: false, //是否完成录音
      audioPath: AudioUtils.DocumentDirectoryPath + '/androidtest.aac', //路径下的文件名
      hasPermission: true, //是否获取权限

      pause: true,

      isPlaying: false
    }
  }

  componentWillMount() {
    DeviceEventEmitter.addListener('playTest', (reminder) => {
      // handle event.
      console.log(e.success);

      if (reminder.name == '暂停播放') {
        this.playSoundPause();
      } else if (reminder.name == '继续播放') {
        this.playSoundPlay();
      } else if (reminder.name == '下一首') {
        this.playSoundNext();
      } else if (reminder.name == '上一首') {
        this.playSoundPrev();
      } else if (reminder.name == '暂停or播放') {
        if (this.state.isPlaying) {
          this.playSoundPause();
        } else {
          this.playSoundPlay();
        }
      } else if (reminder.name == '进度条') {
        // alert(reminder.time);
        playSound.setCurrentTime(reminder.time);
        if (Platform.OS === 'ios') {
          Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', playSound.getDuration(), reminder.time, 1);
        }
        // this.playSoundPrev();
      }
    });
  }

  componentDidMount() {
    // 页面加载完成后获取权限
    this.checkPermission().then((hasPermission) => {
      this.setState({ hasPermission });

      //如果未授权, 则执行下面的代码
      if (!hasPermission) return;
      // this.prepareRecordingPath(this.state.audioPath);

      // AudioRecorder.onProgress = (data) => {
      //   this.setState({currentTime: Math.floor(data.currentTime)});
      // };

      // AudioRecorder.onFinished = (data) => {
      //   if (Platform.OS === 'ios') {
      //     this.finishRecording(data.status === "OK", data.audioFileURL);
      //   }
      // };

    })

    BleManager.start({showAlert: false})
    .then( ()=>{
        //检查蓝牙打开状态，初始化蓝牙后检查当前蓝牙有没有打开
        BleManager.checkState();
        alert('Init the module success.');                
    }).catch(error=>{
        console.log('Init the module fail.');
    });

    //蓝牙状态改变监听
    bleManagerEmitter.addListener('BleManagerDidUpdateState', (args) => {
      console.log('BleManagerDidUpdateState:', args);
      alert(args.state);
      if(args.state == 'on' ){  //蓝牙已打开

      }
    });

    //扫描可用设备，5秒后结束 
    BleManager.scan([], 5, true)
    .then(() => {
        alert('Scan started');
    })
    .catch( (err)=>{
        console.log('Scan started fail');
    });

    //停止扫描
    // BleManager.stopScan()
    // .then(() => {
    //   // Success code
    //   alert('Scan stopped');
    // }).catch( (err)=>{
    //   console.log('Scan stopped fail',err);
    // });

    //搜索到一个新设备监听
    bleManagerEmitter.addListener('BleManagerDiscoverPeripheral', (data) => {
      console.log('BleManagerDiscoverPeripheral:', data);
      // alert(data);
      let id;  //蓝牙连接id
      let macAddress;  //蓝牙Mac地址            
      if(Platform.OS == 'android'){
          macAddress = data.id;
          id = macAddress;
      }else{  
          //ios连接时不需要用到Mac地址，但跨平台识别是否是同一设备时需要Mac地址
          //如果广播携带有Mac地址，ios可通过广播0x18获取蓝牙Mac地址，
          macAddress = getMacAddressFromIOS(data);
          id = data.id;
      }            
    });

    //搜索结束监听
    bleManagerEmitter.addListener('BleManagerStopScan', () => {
      console.log('BleManagerStopScan:','Scanning is stopped'); 
      alert('Scanning is stopped');     
    //搜索结束后，获取搜索到的蓝牙设备列表，如监听了BleManagerDiscoverPeripheral,可省去这个步骤
    BleManager.getDiscoveredPeripherals([])
        .then((peripheralsArray) => {
            console.log('Discovered peripherals: ', peripheralsArray);
            let id = '62393EF6-2084-9BBA-88DC-141621D0594C';
            //连接蓝牙
            BleManager.connect(id)
            .then(() => {
                console.log('Connected');
                //获取蓝牙Service和Characteristics
                BleManager.retrieveServices(id)
                .then((peripheralInfo) => {
                    getUUID(peripheralInfo);
                    console.log('Peripheral info:', peripheralInfo);
                    console.log(nofityServiceUUID);
                    console.log(nofityCharacteristicUUID);
                    //打开通知
                    BleManager.startNotification(id, nofityServiceUUID[0], nofityCharacteristicUUID[0])
                    .then(() => {
                        console.log('Notification started');
                        BleManager.write(id, writeWithResponseServiceUUID[0], writeWithResponseCharacteristicUUID[0], data)
                        .then(() => {
                          // Success code
                          console.log('Write: ' + data);
                        })
                        .catch((error) => {
                          // Failure code
                          console.log(error);
                        });
                        //读取蓝牙数据
                        BleManager.read(id, readServiceUUID[0], readCharacteristicUUID[0])
                        .then((data) => {
                            console.log('Read: ',data);
                        })
                        .catch((error) => {
                            console.log(error);
                        });
                    })
                    .catch((error) => {
                        console.log('Notification error:',error);
                    });
                });  
            })
            .catch((error) => {
                console.log('Connected error:',error);
            });
            // alert(peripheralsArray);
        });
    });

    //接收到新数据监听，开启通知成功后，该监听才可接收到数据
    bleManagerEmitter.addListener('BleManagerDidUpdateValueForCharacteristic', (data) => {
      //ios接收到的是小写的16进制，android接收的是大写的16进制，统一转化为大写16进制
      console.log('BluetoothUpdateValue', data);
      // let value = data.value.toUpperCase();               
      // console.log('BluetoothUpdateValue', value);
    });

    //蓝牙设备已连接监听
    bleManagerEmitter.addListener('BleManagerConnectPeripheral', (args) => {
      console.log('BleManagerConnectPeripheral:', args);
      alert(args.peripheral);
    });

    //蓝牙设备已断开连接监听
    bleManagerEmitter.addListener('BleManagerDisconnectPeripheral', (args) => {
      console.log('BleManagerDisconnectPeripheral:', args);
    });



    NativeAppEventEmitter.addListener(
      'EventReminder',
      (reminder) => {
        // console.log(reminder.name);
        // alert(reminder.name)

        if (reminder.name == '暂停播放') {
          this.playSoundPause();
        } else if (reminder.name == '继续播放') {
          this.playSoundPlay();
        } else if (reminder.name == '下一首') {
          this.playSoundNext();
        } else if (reminder.name == '上一首') {
          this.playSoundPrev();
        } else if (reminder.name == '进度条') {
          // alert(reminder.time);
          playSound.setCurrentTime(reminder.time);
          if (Platform.OS === 'ios') {
            Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', playSound.getDuration(), reminder.time, 1);
          }
          // this.playSoundPrev();
        }
      }
    );
    
  }

  checkPermission() {
    if (Platform.OS !== 'android') {
      return Promise.resolve(true);
    }
    const rationale = {
      'title': '获取录音权限',
      'message': 'XXX正请求获取麦克风权限用于录音,是否准许'
    };
    
    return requestCameraPermission();

    async function requestCameraPermission() {
      
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
          rationale
        )
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          alert('获取权限');
          console.log("You can use the RECORD_AUDIO")
          return PermissionsAndroid.RESULTS.GRANTED;
        } else {
          alert('权限拒绝');
          console.log("RECORD_AUDIO permission denied")
        }
      } catch (err) {
        console.warn(err)
      }
    }
  }

  prepareRecordingPath(audioPath) {
    AudioRecorder.prepareRecordingAtPath(audioPath, {
      SampleRate: 22050,
      Channels: 1,
      AudioQuality: "Low", //录音质量
      MeasurementMode: true,
      AudioEncoding: "aac", //录音格式
      AudioEncodingBitRate: 32000, //比特率
      AudioSource: 7
    });
  }

  async record() {
    // 如果正在录音
    if (this.state.recording) {
      alert('正在录音中!');
      return;
    }
    //如果没有获取权限
    if (!this.state.hasPermission) {
      alert('没有获取录音权限!');
      return;
    }

    this.prepareRecordingPath(this.state.audioPath);

    alert('开始录音!');

    //如果暂停获取停止了录音
    // if(this.state.stoppedRecording){
    //   this.prepareRecordingPath(this.state.audioPath);
    // }

    this.setState({recording: true});

    try {
      const filePath = await AudioRecorder.startRecording();
    } catch (error) {
      console.error(error);
    }
    
  }

  async stop() {
    // 如果没有在录音
    if (!this.state.recording) {
    alert('没有录音, 无需停止!');
    return;
    }
    
    this.setState({stoppedRecording: true, recording: false});
    
    try {
      const filePath = await AudioRecorder.stopRecording();
    
      if (Platform.OS === 'android') {
        this.finishRecording(true, filePath);
      }
      return filePath;
    } catch (error) {
      console.error(error);
    }
  }

  async pause() {
    if (!this.state.recording) {
    alert('没有录音, 无需停止!');
    return;
    }
    
    this.setState({stoppedRecording: true, recording: false});
  
    try {
      const filePath = await AudioRecorder.pauseRecording();
  
      // 在安卓中, 暂停就等于停止
      if (Platform.OS === 'android') {
        alert('12345');
        this.finishRecording(true, filePath);
      }
    } catch (error) {
      console.error(error);
    }
  }

  async resume() {
    if (!this.state.recording) {
    alert('没有录音, 无需继续!');
    return;
    }
    
    this.setState({stoppedRecording: true, recording: false});
  
    try {
      const filePath = await AudioRecorder.resumeRecording();
  
      // 在安卓中, 暂停就等于停止
      // if (Platform.OS === 'android') {
      //   alert('12345');
      //   this.finishRecording(true, filePath);
      // }
    } catch (error) {
      console.error(error);
    }
  }

  finishRecording(didSucceed, filePath) {
    this.setState({ finished: didSucceed });
    console.log('Finished recording of duration');
  }

  playSound() {
    if (Platform.OS === 'ios') {
      Manager.viewDidLoad();
      Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', 0, 0, 0);
    } else {
      // alert('开始');
      ToastExample.initSession();
    }
    playSound = new Sound('http://fs.w.kugou.com/201812130940/b2b5ca0580f6fc58e53bd5d4549ad750/G143/M0A/18/0F/L4cBAFu6wreAXCUXADZS77jF37k426.mp3', null, (error) => {
      if (error) {
        console.log('failed to load the sound', error);
      }
      console.log('duration in seconds: ' + playSound.getDuration() + 'number of channels: ' + playSound.getNumberOfChannels());
      if (Platform.OS === 'ios') {
        Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', playSound.getDuration(), 0, 1);
      } else {
        // ToastExample.showNotification(true);
        ToastExample.updatePlaybackState(0);
        ToastExample.updateLocMsg('歌曲1', '作者1', '专辑1', playSound.getDuration());
      }
      this.setState({
        isPlaying: true
      })
      alert('开始播放');
      playSound.play((success) => {
        if (success) {
          alert('播放完成');
          if (Platform.OS === 'ios') {
            Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', playSound.getDuration(), playSound.getDuration(), 1);
          } else {
            ToastExample.updatePlaybackState(1);
          }
          this.setState({
            isPlaying: false
          })
          this.playSoundNext();
          console.log('successfully finished playing');
        } else {
          console.log('playback failed due to audio decoding errors');
        }
      });
    });

    
  }

  playSoundPrev() {
    // Manager.viewDidLoad();
    playSound.release();
    // playSound.stop(() => {
      playSound = new Sound('http://fs.w.kugou.com/201812130940/367b1c014910e05b576389f40bcad1f4/G150/M00/08/01/1g0DAFwJ94GAZ3BmACmxewG0CHI388.mp3', null, (error) => {
        if (error) {
          console.log('failed to load the sound', error);
        }
        console.log('duration in seconds: ' + playSound.getDuration() + 'number of channels: ' + playSound.getNumberOfChannels());
        if (Platform.OS === 'ios') {
          Manager.showLockScreenTotaltime('歌曲0', '作者0', '专辑0', playSound.getDuration(), 0, 1);
        } else {
          ToastExample.updatePlaybackState(0);
          ToastExample.updateLocMsg('歌曲0', '作者0', '专辑0', playSound.getDuration());
        }
        this.setState({
          isPlaying: true
        })
        alert('开始播放');
        playSound.play((success) => {
          if (success) {
            alert('播放完成');
            if (Platform.OS === 'ios') {
              Manager.showLockScreenTotaltime('歌曲0', '作者0', '专辑0', playSound.getDuration(), playSound.getDuration(), 1);
            } else {
              ToastExample.updatePlaybackState(1);
            }
            this.setState({
              isPlaying: false
            })
            this.playSoundNext();
            console.log('successfully finished playing');
          } else {
            console.log('playback failed due to audio decoding errors');
          }
        });
      });
    // })
    
  }

  playSoundNext() {
    // Manager.viewDidLoad();
    playSound.release();
    // playSound.stop(() => {
      playSound = new Sound('http://fs.w.kugou.com/201812130941/0801ca56968acdaf14a798df78e25c34/G125/M0B/11/15/XZQEAFwHOKuAQo7dAE0mYI9Aa60360.mp3', null, (error) => {
        if (error) {
          console.log('failed to load the sound', error);
        }
        console.log('duration in seconds: ' + playSound.getDuration() + 'number of channels: ' + playSound.getNumberOfChannels());
        if (Platform.OS === 'ios') {
          Manager.showLockScreenTotaltime('歌曲2', '作者2', '专辑2', playSound.getDuration(), 0, 1);
        } else {
          ToastExample.updatePlaybackState(0);
          ToastExample.updateLocMsg('歌曲2', '作者2', '专辑2', playSound.getDuration());
        }
        this.setState({
          isPlaying: true
        })
        alert('开始播放');
        playSound.play((success) => {
          if (success) {
            alert('播放完成');
            if (Platform.OS === 'ios') {
              Manager.showLockScreenTotaltime('歌曲2', '作者2', '专辑2', playSound.getDuration(), playSound.getDuration(), 1);
            } else {
              ToastExample.updatePlaybackState(1);
            }
            this.setState({
              isPlaying: false
            })
            this.playSoundPrev();
            console.log('successfully finished playing');
          } else {
            console.log('playback failed due to audio decoding errors');
          }
        });
      });
    // })
  }

  playSoundPause() {
    playSound.getCurrentTime((seconds) => {
      console.log('at ' + seconds);
      if (Platform.OS === 'ios') {
        Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', playSound.getDuration(), seconds, 0);
      } else {
        ToastExample.updatePlaybackState(1);
        ToastExample.updateLocMsg('歌曲1', '作者1', '专辑1', playSound.getDuration());
      }
    });
    this.setState({
      isPlaying: false
    })
    playSound.pause();
    

  }

  playSoundPlay() {
    playSound.getCurrentTime((seconds) => {
      console.log('at ' + seconds);
      if (Platform.OS === 'ios') {
        Manager.showLockScreenTotaltime('歌曲1', '作者1', '专辑1', playSound.getDuration(), seconds, 1);
      } else {
        ToastExample.updatePlaybackState(0);
        ToastExample.updateLocMsg('歌曲1', '作者1', '专辑1', playSound.getDuration());
      }
    });
    this.setState({
      isPlaying: true
    })
    playSound.play();
    
  }

  async play() {
    // 如果在录音 , 执行停止按钮
    if (this.state.recording) {
    await this.stop();
    }
    
    // 使用 setTimeout 是因为, 为避免发生一些问题 react-native-sound中
    setTimeout(() => {
      let sound = new Sound(this.state.audioPath, '', (error) => {
        if (error) {
          console.log('failed to load the sound', error);
        }
        console.log('duration in seconds: ' + sound.getDuration() + 'number of channels: ' + sound.getNumberOfChannels());
        alert('开始播放');
      });

      setTimeout(() => {
        sound.play((success) => {
          if (success) {
            alert('播放完成');
            console.log('successfully finished playing');
          } else {
            console.log('playback failed due to audio decoding errors');
          }
        });
      }, 100);
      

      // Manager.setupLockScreenInfo('123', '234');
      // Manager.createRemoteCommandCenter((data) => {
      //   alert(data);
      //   // if (data == '暂停') {
      //   //   sound.pause();
      //   // } else {
      //   //   sound.play();
      //   // }
      //   // Manager.setupLockScreenInfo('456', '567');
      // });
      console.log(sound);
    
      
    }, 100);
  }




  render() {
    return (
      <View style={styles.container}>
        <Button
          onPress={this.record}
          title="录音"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
        <Button
          onPress={this.stop}
          title="停止录音"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
        <Button
          onPress={this.pause}
          title="暂停录音"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
        <Button
          onPress={this.resume}
          title="继续录音"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
        <Button
          onPress={this.play}
          title="播放录音"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
        <Video
          source={{uri: 'http://fs.w.kugou.com/201812051401/458fdc8d26ebff3c921791261bc94ef7/G083/M07/1E/10/M5QEAFgvQgWATvYEAEBvKnQO8lk294.mp3'}}
          ref='video'
          // rate={1}
          volume={1.0}
          paused={this.state.pause}
          onProgress={(e) => {}}
          onLoad={(e) => {}} />
        <Button
          onPress={() => { this.setState({pause: !this.state.pause})}}
          title="播放video"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
        <Button
          onPress={() => {this.setState({pause: !this.state.pause})}}
          title="暂停video"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />

        <Button
          onPress={this.playSound}
          title="播放sound"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />

        <Button
          onPress={this.playSoundPause}
          title="暂停sound"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />

        <Button
          onPress={this.playSoundPlay}
          title="继续sound"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />

        <Button
          onPress={this.playSoundPrev}
          title="上一首"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />

        <Button
          onPress={this.playSoundNext}
          title="下一首"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
